<?php
/*****************************************************************************\
+-----------------------------------------------------------------------------+
| TrackIT                                                                     |
| Copyright (c) 2008 Leonard P. Boyce <leonard@usethesource.net>              |
| All rights reserved.                                                        |
+-----------------------------------------------------------------------------+
| PLEASE READ  THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "LICENSE"   |
| FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE  |
| AT THE FOLLOWING URL: http://www.usethesource.net/license.php               |
|                                                                             |
| THIS  AGREEMENT  EXPRESSES  THE  TERMS  AND CONDITIONS ON WHICH YOU MAY USE |
| THIS SOFTWARE   PROGRAM   AND  ASSOCIATED  DOCUMENTATION   THAT  LEONARD P. |
| BOYCE (hereinafter  referred to as "THE AUTHOR") IS FURNISHING  OR MAKING   |
| AVAILABLE TO YOU WITH  THIS  AGREEMENT  (COLLECTIVELY,  THE  "SOFTWARE").   |
| PLEASE   REVIEW   THE  TERMS  AND   CONDITIONS  OF  THIS  LICENSE AGREEMENT |
| CAREFULLY   BEFORE   INSTALLING   OR  USING  THE  SOFTWARE.  BY INSTALLING, |
| COPYING   OR   OTHERWISE   USING   THE   SOFTWARE,  YOU  AND  YOUR  COMPANY |
| (COLLECTIVELY,  "YOU")  ARE  ACCEPTING  AND AGREEING  TO  THE TERMS OF THIS |
| LICENSE   AGREEMENT.   IF  YOU    ARE  NOT  WILLING   TO  BE  BOUND BY THIS |
| AGREEMENT, DO  NOT INSTALL OR USE THE SOFTWARE.  VARIOUS   COPYRIGHTS   AND |
| OTHER   INTELLECTUAL   PROPERTY   RIGHTS    PROTECT   THE   SOFTWARE.  THIS |
| AGREEMENT IS A LICENSE AGREEMENT THAT GIVES  YOU  LIMITED  RIGHTS   TO  USE |
| THE  SOFTWARE   AND  NOT  AN  AGREEMENT  FOR SALE OR FOR  TRANSFER OF TITLE.|
| THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT.      |
|                                                                             |
| The Initial Developer of the Original Code is Leonard P. Boyce              |
| Portions created by Leonard P. Boyce are Copyright (C) 2008                 |
| Leonard P. Boyce. All Rights Reserved.                                      |
+-----------------------------------------------------------------------------+
\*****************************************************************************/



/**
 *  Mailer Class
 *
 *  Set up configuration of mailer object used for sending emails
 *
 *  Extends 3rdparty phpmailer class (See Util/3rdParty/PHPMailer.class.php
 *
 *  @author     Vinod Kumar
 *  @version    $Revision: 1.0$
 *  @package    Project name
 *
 */
class Mailer extends PHPMailer
{
    /*
    *   From Email
    */
    public $From     = "";

    /*
    *   From Name
    */
    public $FromName = "";

    /*
    *   Mailer
    */
    public $Mailer   = "sendmail";

    /*
    *   Word Wrap Limit
    */
    public $WordWrap = 75;

    /*
    *   Word Wrap Limit
    */
    public $ContentType = "text/plain";

    /*
    *   Database connection
    */
    private $db;

    /**
     *  __construct
     *
     *  Set up user class and objects
     *
     *  @param      object      database    PDO database connection object
     */
    public function __construct(PDO $database) {
        $this->db = $database;
        $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $this->__initSettings();
    }/*END __construct*/


    /**
     *  __initSettings
     *
     *  Load & initializes default mail settings
     *
     */
    private function __initSettings() {

        global $CONF, $util;

        $settings = $util->getEmailSettings();

        // Set the default from address details if not set already
        if ($this->From == "") {
            $this->From = $settings['EML_SENDMAIL_FROM_EMAIL_ID'];
        }
        if ($this->FromName == "") {
            $this->FromName = $settings['EML_SENDMAIL_FROM_NAME'];
        }
        switch (strtolower($settings['EML_MAILER'])) {

            case 'smtp': {
                $this->IsSMTP();
                $this->Host     = $settings['EML_SMTP_HOST'];
                $this->SMTPAuth = $settings['EML_SMTP_AUTH'];
                $this->Username = $settings['EML_SMTP_USER'];
                $this->Password = $settings['EML_SMTP_PASS'];
                if(isset($settings['EML_SMTP_PORT']) && $settings['EML_SMTP_PORT']!='') {
                    $this->Port = $settings['EML_SMTP_PORT']; //Default 25
                }
                if(isset($settings['EML_SMTP_SECURE']) && $settings['EML_SMTP_SECURE']!='') {
                    $this->SMTPSecure   = $settings['EML_SMTP_SECURE'];// Option ssl/tsl
                }
                break;
            }
            case 'sendmail': {
                $this->IsSendmail();
                break;
            }
            case 'qmail': {
                $this->IsQmail();
                break;
            }
            default: {
                $this->IsMail();
            }
        }
    }/*END __initSettings*/

}/*END Mailer Class*/
?>